package com.pingan.springboot_es_api.service;

import com.pingan.springboot_es_api.domain.Demo;
import org.frameworkset.elasticsearch.ElasticSearchHelper;
import org.frameworkset.elasticsearch.client.ClientInterface;
import org.frameworkset.elasticsearch.entity.ESDatas;
import org.springframework.stereotype.Service;

/**
 * Created by Kay on 2018/10/28
 */
@Service
public class DemoServiceImpl implements DemoService{

    @Override
    public Demo SearchById(String id) {
        //创建创建/修改/获取/删除文档的客户端对象，单实例多线程安全
            ClientInterface clientUtil = ElasticSearchHelper.getRestClientUtil();
            Demo response = clientUtil.getDocument("demo",//索引表
                    "demo",//索引类型
                    id,
                    Demo.class);//w
            return response;
    }

    @Override
    public ESDatas<Demo> SearchAll() {

            ClientInterface clientUtil = ElasticSearchHelper.getConfigRestClientUtil("esmapper/demo.xml");
            return clientUtil.searchList("demo/_search","searchAll",Demo.class);

    }
}
